//
// Description: 201. 数字范围按位与
// Created by Loading on 2025/4/5.
//

#include <bits/stdc++.h>

using namespace std;

int rangeBitwiseAnd(int left, int right) {
    /// 寻找所有数的二进制表示的最长公共前缀，后边全是0
    // Brian Kernighan 算法，每次清除最后边的1，直到left>=right
    while (left < right) {
        right &= (right - 1);
    }
    return right;
}

int main() {
    int left = 9;
    int right = 12;

    auto res = rangeBitwiseAnd(left, right);

    cout << res << endl;

    return 0;
}
